#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>



int main (int args, char * argv[] )
{
int i;



  SDL_Init( SDL_INIT_EVERYTHING );
  SDL_Surface * ecran=NULL ,* bg=NULL,* perso[4],*balle[3];



 SDL_Rect persoPosition;
 persoPosition.x=600;
 persoPosition.y=300;

  ecran=SDL_SetVideoMode( 800,600 , 32 ,SDL_HWSURFACE );
  bg=IMG_Load("bg.jpg");
  balle[0]=IMG_Load("balle1.png");
  balle[1]=IMG_Load("balle2.png");
  balle[2]=IMG_Load("balle3.png");


  SDL_Rect position;
  position.x=0;
  position.y=0;
 
  



perso[0]=IMG_Load("b1.png");
perso[1]=IMG_Load("b2.png");
perso[2]=IMG_Load("b3.png");
perso[3]=IMG_Load("b4.png");













SDL_BlitSurface(bg,NULL,ecran,&position);
SDL_BlitSurface(balle[0],NULL,ecran,&persoPosition);
SDL_BlitSurface(perso[0],NULL,ecran,&persoPosition);
SDL_FreeSurface(bg);
SDL_FreeSurface(balle[0]);
SDL_FreeSurface(perso[0]);



  SDL_Flip(ecran);






while(1)
{    SDL_Event event;
     SDL_WaitEvent(&event);

if(event.type==SDL_QUIT) 
{
break; 
}

else if(event.type==SDL_KEYDOWN)
{
if(event.key.keysym.sym==SDLK_ESCAPE)
{
break ;


}

if(event.key.keysym.sym==SDLK_RIGHT)
{
persoPosition.x+=600;






  SDL_BlitSurface(bg,NULL,ecran,&position);


  SDL_BlitSurface(perso[0],NULL,ecran,&persoPosition);
  SDL_Flip(ecran);

}

if(event.key.keysym.sym==SDLK_LEFT)

{
persoPosition.x-=600;

  SDL_BlitSurface(bg,NULL,ecran,&position);

  SDL_BlitSurface(perso[3],NULL,ecran,&persoPosition);
  SDL_FreeSurface(perso[3]);
  SDL_Flip(ecran);

}

if(event.key.keysym.sym==SDLK_UP)
{
if (persoPosition.x==0 && persoPosition.y==600)
{

SDL_BlitSurface(perso[3],NULL,ecran,&persoPosition);
SDL_FreeSurface(perso[3]);
SDL_Flip(ecran);

}
if(persoPosition.x==800 && persoPosition.y==600)
{
SDL_BlitSurface(perso[1],NULL,ecran,&persoPosition);
SDL_FreeSurface(perso[1]);
SDL_Flip(ecran);

}

}










}



 



}







SDL_FreeSurface(ecran);
SDL_FreeSurface(bg);

SDL_Quit();
return 0 ;



}
